home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
-
- #include "EntryDialog.h"
- #include "Entry.h"
- #include <Vk/VkPrefItem.h>
- #include "DayView.h"
- #include "Utils.h"
- #include "Preferences.h"
- #include <Vk/VkWarningDialog.h>
-
- #include <Xm/Form.h>
- #include <Xm/LabelG.h>
- #include <Xm/PushB.h>
- #include <Xm/SeparatoG.h>
- #include <Xm/RowColumn.h>
-
- static int count;
- static Arg args[10];
-
- void EntryDialog::kind_stub(Widget w, XtPointer client_data, XtPointer)
- {
- EntryDialog *obj = (EntryDialog *) client_data;
-
- obj->newKind(w);
- }
-
- /**********************************************************************/
-
- EntryDialog::EntryDialog(Entry *e, DayView *o, const char *name) : VkPrefDialog(name)
- {
- owner = o;
- _entry = e;
-
- list = NULL;
-
- list = new VkPrefList("entryAttributes");
- label = new VkPrefLabel("label");
- separator = new VkPrefSeparator("separator");
- group = new VkPrefGroup("group", False, True);
- kind = new VkPrefOption("kind", entryKindCount);
- annotate = new VkPrefToggle("annotate");
- notifyPopup = new VkPrefToggle("notifyPopup", True);
- notifyBell = new VkPrefToggle("notifyBell", True);
- notifyMail = new VkPrefToggle("notifyMail", True);
- notifyCommand = new VkPrefText("notifyCommand", 40);
- advance = new VkPrefText("advance");
- repeat = new VkPrefText("repeatEnd");
-
- group->addItem(kind);
- group->addItem(annotate);
- group->addItem(notifyPopup);
- group->addItem(notifyBell);
- group->addItem(notifyMail);
- group->addItem(notifyCommand);
- group->addItem(advance);
- group->addItem(repeat);
- list->addItem(label);
- list->addItem(separator);
- list->addItem(group);
- setItem(list);
-
- updateDisplay();
- }
-
- Widget EntryDialog::createDialog(Widget parent)
- {
- int each;
- XmString xs;
- char str[256], *cstr, *p;
-
- Widget dialog = VkPrefDialog::createDialog(parent);
-
- formatDate(_entry->day(), _entry->month(), _entry->year(), str);
- strcat(str, ", ");
- formatTime(_entry->start() / 60, _entry->start() % 60,
- thePreferences->clock24(), str+strlen(str));
- strcat(str, ": ");
- cstr = strdup(_entry->text());
- if (p = strchr(cstr, '\n')) {
- *p = '\0';
- strcat(str, cstr);
- strcat(str, "...");
- } else {
- strcat(str, cstr);
- }
- xs = XmStringCreateSimple(str);
- count = 0;
- XtSetArg(args[count], XmNlabelString, xs); count++;
- XtSetValues(label->baseWidget(), args, count);
- XmStringFree(xs);
- free(cstr);
- for (each=0; each<entryKindCount; each++)
- {
- kind->setLabel(each, entryKindList[each].string);
- XtAddCallback(kind->getButton(each), XmNactivateCallback,
- EntryDialog::kind_stub, (XtPointer) this);
- }
-
- return dialog;
- }
-
- /**********************************************************************/
-
- void EntryDialog::apply(Widget, XtPointer)
- {
- doApply();
- }
-
- void
- EntryDialog::updateDisplay()
- {
- char str[256];
- int each;
- RepeatingEntry *rentry;
-
- annotate->setValue(_entry->annotate());
- notifyPopup->setValue(_entry->notifyPopup());
- notifyBell->setValue(_entry->notifyBell());
- notifyMail->setValue(_entry->notifyMail());
- notifyCommand->setValue(_entry->notifyCommand());
- advance->setValue(_entry->alarmAdvance());
- for (each=0; each<entryKindCount; each++) {
- if (entryKindList[each].kind == _entry->kind()) {
- kind->setValue(each);
- break;
- }
- }
- if (_entry->repeating()) {
- rentry = (RepeatingEntry *) _entry;
- formatDate(rentry->repeatEndDay(), rentry->repeatEndMonth(),
- rentry->repeatEndYear(), str);
- repeat->setValue(str);
- repeat->activate();
- } else {
- repeat->setValue("");
- repeat->deactivate();
- }
- }
-
- Boolean
- EntryDialog::doApply()
- {
- char *str;
- int day, month, year;
- Entry *nentry;
- Boolean result;
- EntryKind entryKind;
-
- list->updateValue();
- result = True;
- entryKind = entryKindList[kind->getValue()].kind;
- if (entryKind != _entry->kind() &&
- _entry->repeating() && entryKind == E_single) {
- nentry = new Entry();
- nentry->setDate(_entry->day(), _entry->month(), _entry->year());
- nentry->setTime(_entry->start(), _entry->length());
- nentry->setText(_entry->text());
- _entry = nentry;
- } else if (entryKind != _entry->kind() &&
- !_entry->repeating() && entryKind != E_single) {
- nentry = new RepeatingEntry();
- nentry->setDate(_entry->day(), _entry->month(), _entry->year());
- nentry->setTime(_entry->start(), _entry->length());
- nentry->setText(_entry->text());
- _entry = nentry;
- }
- _entry->setKind(entryKind);
- _entry->setAnnotate(annotate->getValue());
- _entry->setNotifyPopup(notifyPopup->getValue());
- _entry->setNotifyBell(notifyBell->getValue());
- _entry->setNotifyMail(notifyMail->getValue());
- _entry->setNotifyCommand(notifyCommand->getValue());
- if (_entry->setAlarmAdvance(advance->getValue())) {
- advance->setValue(_entry->alarmAdvance());
- } else {
- theWarningDialog->post("Illegal alarm advance notice value.", NULL, this);
- result = False;
- }
- if (_entry->repeating()) {
- str = repeat->getValue();
- if (parseDate(str, &day, &month, &year)) {
- ((RepeatingEntry *) _entry)->setRepeatEnd(day, month, year);
- } else {
- theWarningDialog->post("Couldn't parse repeat end date.", NULL, this);
- result = False;
- }
- XtFree(str);
- }
- updateDisplay();
- owner->entryChanged(this);
- return result;
- }
-
- void
- EntryDialog::newKind(Widget w)
- {
- int each;
- Entry test;
-
- for (each=0; each<entryKindCount; each++) {
- if (kind->getButton(each) == w) {
- test.setKind(entryKindList[each].kind);
- if(test.repeating())
- repeat->activate();
- else
- repeat->deactivate();
- }
- }
- }
-
- /**********************************************************************/
-
- EntryDialog::~EntryDialog()
- {
- if (list) {
- list->deleteChildren();
- delete list;
- }
- }
-
-